package com.itheima;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.function.Consumer;

public class HashSetDemo {
    public static void main(String[] args){

        LinkedList<String> list = new LinkedList<>();
        list.add("zhangsan");
        list.add("zhangsan");
        list.add("zhangsan");
        list.add("zhangsan");
        System.out.println(list);

        ArrayList<String> newList = new ArrayList<>((new HashSet<>(list)));
        System.out.println(newList);


        //1.创建一个HashSet对象
        HashSet<String> hashSet = new HashSet<>();

        //2.保存数据
        hashSet.add("Aima");
        hashSet.add("Lily");
        hashSet.add("Anne");
        hashSet.add("ailisi");
        hashSet.add("memory");
        System.out.println(hashSet);

        //3.取数据（迭代器）
        Iterator<String> iterator = hashSet.iterator();
        while (iterator.hasNext()){
            String next = iterator.next();
            System.out.println(next);
        }
//        for (int i; i < hashSet.size(); i++){
//
//        }

        //4.取数据（增强for循环）
        for(String name : hashSet){
            System.out.println("name = "+name);
        }

        int[] arr = {10,9,8,7,6,5,4,3,2,1};
        for (int i : arr){
            System.out.println(i);
        }

        //5.取数据（Lambda)
        hashSet.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });

        hashSet.forEach(s ->System.out.println(s));
        hashSet.forEach(System.out::println);

        Student student = new Student("三张",20);
        System.out.println(student);

    }
}
